﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACP.DTO;

namespace ACP.Data
{
    public class ResultsRepository : Repository<result>
    {
        // Add your own data access methods.
        // This file should not get overridden

        public static result GetResultById(int id)
        {
            IRepository<result> resultsRepository = new Repository<result>();
            result resultEntity;
            try
            {
                resultEntity = resultsRepository.First(q => q.testid == id);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                resultsRepository.Dispose();
            }
            return resultEntity;
        }

        public static result GetResultsWithAssociations(int _testId)
        {
            Repository<result> resultsRepository = new Repository<result>();
            result resultEntity;
            try
            {
                resultEntity = resultsRepository.First(r => r.testid == _testId);
                resultEntity.user = resultEntity.user;
                resultEntity.examtype = resultEntity.examtype;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                resultsRepository.Dispose();
            }
            return resultEntity;
        }

        public static void InsertCurrentExamInformation(result _result)
        {
            Repository<result> resultRepository = new Repository<result>();
            try
            {
                resultRepository.Add(_result);
                resultRepository.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                resultRepository.Dispose();
            }
        }

        public static void UpdateResult(result resultObject)
        {
            Repository<result> resultsRepository = new Repository<result>();
            try
            {
                resultsRepository.Update(resultObject);
                resultsRepository.UnitOfWork.Commit();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                resultsRepository.Dispose();
            }
        }
    }
}
